package com.itts.Factory;

import com.itts.Validator.LisPlanValidatorFactory;
import com.itts.common.utils.result.Query;
import com.itts.common.utils.result.R;
import com.itts.controller.BaseController;
import com.itts.converter.ConverterFactory;
import com.itts.entity.dto.ApproveProgressDTO;
import com.itts.service.IAccessRecordService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/accessRecord")
public class TestController extends BaseController {

    @Autowired
    private IAccessRecordService accessRecordService;

    /**
     * 分页查询（PC端）
     *
     * @param params
     * @return
     */
    @GetMapping("/page")
    public R page(@RequestParam Map<String, Object> params) {
        Query query = new Query(params);
        return success(accessRecordService.pageAccessRecord(query));
    }

    /**
     * 访客分页查询（PC端）
     *
     * @param
     * @return
     */
    @GetMapping("/pageVisitor")
    public R pageVisitor(@RequestParam Req<LisProposavVo> req) {
        List<String> validate = ValidayFactory.getValidator(LisProposavVo.class).validate(req);
        if (CollectionUtils.isNotEmpty(validate)){
            throw new RuntimeException("校验不通过");
        }
        List<String> error = LisPlanValidatorFactory.getValidator("安康C款").validate(new ApproveProgressDTO());
        LisProposavDTO dto = ConverterFactory.getConverter(LisProposavVo.class, LisProposavDTO.class).convert(req.getBody);
    }
 }
